﻿@using zichan.Entity;

@{
    List<Menu> menus = zichan.Common.PowerHelp.GetUserMenu();
    string controller = ViewContext.RouteData.Values["Controller"].ToString().ToLower();
    string action = ViewContext.RouteData.Values["Action"].ToString().ToLower();
}

<div class="page-sidebar-wrapper">

    <div class="page-sidebar navbar-collapse collapse">
        <!-- BEGIN SIDEBAR MENU -->

        <ul class="page-sidebar-menu" data-keep-expanded="false" data-auto-scroll="true" data-slide-speed="200">
            <li class="sidebar-toggler-wrapper stars">
                <div class="sidebar-toggler hidden-phone"><h3 style="margin-left:-140px; line-height:23px;  color:#666; margin-top:0px; ">功能菜单</h3></div>
            </li>

            @foreach (Menu m in menus.Where(o => o.Level == 0).OrderBy(o => o.Sort).ToList())
            {
                List<Menu> submenus = menus.Where(o => o.Level == 1 && o.Path.Contains("," + m.Id + ",")).OrderBy(o => o.Sort).ToList();
                bool Selected = menus.Count(o => o.Path.Contains("," + m.Id + ",") && o.Controller == controller && o.Action == action) > 0;
                if (submenus.Count() > 0)
                {
                    <li class="@Html.Raw(Selected ? "active open" : "")">
                        <a href="javascript:;">
                            <i class="@m.Ico"></i>
                            <span class="title">@m.Title</span>
                            <span class="arrow @(Selected ? "open" : "")"></span>
                        </a>

                        <ul class="sub-menu">
                            @foreach (Menu subm in submenus)
                            {
                                bool Selected2 = subm.Controller == controller && subm.Action == action;
                                bool Selected3 = menus.Count(o => o.Path.Contains("," + subm.Id + ",") && o.Controller == controller && o.Action == action) > 0;
                                <li class="@Html.Raw((Selected2 || Selected3) ? "active" : "")">
                                    <a href="@Url.Action(subm.Action, subm.Controller)">
                                        @subm.Title
                                    </a>
                                </li>
                            }
                        </ul>
                    </li>
                }
                else
                {
                    bool Selected2 = m.Controller == controller && m.Action == action;
                    <li class="@Html.Raw(Selected || Selected2 ? "active" : "")">
                        <a href="@Url.Action(m.Action, m.Controller)">
                            <i class="@m.Ico"></i>
                            <span class="title">@m.Title</span>
                        </a>
                    </li>
                }
            }

        </ul>
        <!-- END SIDEBAR MENU -->
    </div>
</div>



@*@foreach (var group in adminMenuConfig.AdminMenuGroups)
    {
        if (!string.IsNullOrEmpty(group.Permission) && !permissions.Contains(group.Permission))
        {
            continue;
        }

        var menus = group.AdminMenuArray.Where(m => string.IsNullOrEmpty(m.Permission) || permissions.Contains(m.Permission));
        var hasSub = menus.Count() > 0;

        if (!hasSub && string.IsNullOrEmpty(group.Url))
        {
            continue;
        }

        <li class="@(hasSub?"has-sub":string.Empty)">
            <a href="@(hasSub ? "javascript:;" : group.Url)" title="@group.Info">
            <i class="@group.Icon"></i>
            <span class="title">@group.Name</span>
            @if (hasSub)
            {
                <span class='arrow'></span>
            }
            </a>
            @if (hasSub)
            {
                <ul class="sub">
                @foreach (var menu in menus)
                {
                    <li ><a href="@menu.Url" title="@menu.Info">@menu.Name</a></li>
                }
                </ul>
            }
        </li>
    }*@


